﻿using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using Ops.Mpc.Ioc.MessageBoxServices;

namespace Ops.Mpc.ExampleApplication.FancyMessageBox
{
    public partial class MessageBoxControl : ChildWindow
    {
        #region Static Methods
        public static void Show(string message, string caption, System.Windows.MessageBoxButton messageBoxButton, MessageBoxResultHandler messageBoxResultHandler = null)
        {
            MessageBoxControl messageBoxControl = new MessageBoxControl(caption);

            if (!string.IsNullOrWhiteSpace(message))
                messageBoxControl.TextBlock.Text = message;

            messageBoxControl.CancelButton.Visibility = messageBoxButton == MessageBoxButton.OKCancel ? Visibility.Visible : Visibility.Collapsed;

            messageBoxControl.Show();

        }

        #endregion
        #region Methods

        private MessageBoxControl(string title)
        {
            this.Title = title;
            InitializeComponent();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        // Offer ESC key support for closing the ChildWindow:
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                DialogResult = false;
                e.Handled = true;
            }

            base.OnKeyDown(e);
        }
        #endregion

    }
}
